/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package planspiel.panels.subpanels;

import javax.swing.GroupLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import planspiel.BudgetTimer;
import planspiel.GameRoundController;
import planspiel.panels.GameScreen;

/**
 *
 * @author Administrator
 */
public class GameHeader extends JPanel {

	private static final long serialVersionUID = 4274476217255812320L;
	private GameScreen gameScreen = null;
    private JLabel title = new JLabel();
    private JLabel score = new JLabel();
    private JLabel time = new JLabel();
    private JLabel instruction = new JLabel();
    
    /**
     * 
     * @param gameScreen
     */
    public GameHeader(GameScreen gameScreen) {
        this.gameScreen = gameScreen;
        initDisplay();
    }
    
    private void initDisplay() {
        GameRoundController gameController = gameScreen.getGame().getCurrentGameRoundController();
        
        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        
        //Init alignment
        title.setHorizontalAlignment(SwingConstants.CENTER);
        score.setHorizontalAlignment(SwingConstants.CENTER);
        time.setHorizontalAlignment(SwingConstants.CENTER);
        instruction.setHorizontalAlignment(SwingConstants.CENTER);
                
        //Init title
        int roundID = gameScreen.getGame().getCurrentGameRoundController().getRoundID();
        title.setText(roundID + ". round");

        //Init timer
        gameScreen.getGame().getCurrentGameRoundController().getCountdownTimer().addChangedListener(time);
        BudgetTimer budgetTimer = gameScreen.getGame().getCurrentGameRoundController().getBudgetTimer();
        if (budgetTimer != null) {
        	budgetTimer.addChangedListener(score);
        }

        //Init instruction
        if(gameController.getSelectedGameStage() == GameRoundController.VACANCYSTAGE){
            if(gameController.getSelectedVacancy() == null){
                instruction.setText("Please select a vacancy for the current round");
            } else {
                instruction.setText("A vacancy for the current round has already been selected");
            }
        } else if(gameController.getSelectedGameStage() == GameRoundController.PLATFORMSTAGE){
            if(gameController.getSelectedPlatform() == null){
                instruction.setText("Please select a platform for the current round");
            } else {
                instruction.setText("A platform for the current round has already been selected");
            }
        } else if(gameController.getSelectedGameStage() == GameRoundController.CANDIDATESTAGE){
                instruction.setText("Please select the candidate of your choice for the current round. The round will be finished as soon as you pick a candidate!");
        } else if(gameController.getSelectedGameStage() == GameRoundController.MESSAGESTAGE){
                instruction.setText("You can check your mails by selecting a person in the list on the left.");
        } else if(gameController.getSelectedGameStage() == GameRoundController.TIPSTAGE){
                instruction.setText("The tip should help you to become more successfull in this game :-)");
        }
        
        //Init score
        if(gameController.getSelectedVacancy() != null){
            score.setText(gameScreen.getGame().getGameRound().getScoreAsString());
        } else {
            score.setText(" - ");
        }
        
        //Init layout
        layout.setHorizontalGroup(
            layout.createParallelGroup()
                .addComponent(title, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(score, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(time, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                )
                .addComponent(instruction, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        layout.setVerticalGroup(
            layout.createSequentialGroup()
                .addComponent(title, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup()
                    .addComponent(score, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(time, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                )
                .addComponent(instruction, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }

	/**
	 * @return the title
	 */
	public JLabel getTitle() {
		return title;
	}

	/**
	 * @return the score
	 */
	public JLabel getScore() {
		return score;
	}

	/**
	 * @return the time
	 */
	public JLabel getTime() {
		return time;
	}

	/**
	 * @return the instruction
	 */
	public JLabel getInstruction() {
		return instruction;
	}
}
